import java.io.IOException;
import java.sql.SQLException;

import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;

import org.protege.owlapi.apibinding.ProtegeOWLManager;
import org.protege.owlapi.database.DatabaseOntologyFactory;
import org.protege.owlapi.database.DatabaseSupport;
import org.protege.owlapi.model.ProtegeOWLOntologyManager;


public class OntologyStorerDB {
//	public static String ONTOLOGY   = "http://www.co-ode.org/ontologies/pizza/pizza.owl";
//    public static String DB_PREFIX  = "pizza";
    
    public static String ONTOLOGY   = "http://owl-test.googlecode.com/svn/trunk/ontology/RoutingModel.owl";
    public static String DB_PREFIX  = "routing";
    
	public static void main(String[] args) {
		 System.out.println("Adding the ontology " + ONTOLOGY + " to the database with the database prefix " + DB_PREFIX);
	        ProtegeOWLOntologyManager manager = ProtegeOWLManager.createOWLOntologyManager();
	        DatabaseOntologyFactory dbFactory = null;
	        
			try {
				dbFactory = DatabaseSupport.useDatabaseOntologyFactory(manager, 
	                                                       "jdbc:mysql://localhost/test", 
	                                                       "johann", 
	                                                       "");
			} catch (ClassNotFoundException | IOException | SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
	        dbFactory.setPrefix(DB_PREFIX); // optional
	        
	        try {
				manager.loadOntologyFromOntologyDocument(IRI.create(ONTOLOGY));
			} catch (OWLOntologyCreationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	        
	        OWLOntology ontology = manager.getOntology(IRI.create(ONTOLOGY));
	        System.out.println("Axiom count = " + ontology.getAxioms().size());
	        
	}

}
